<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
  xmlns:a4j="http://richfaces.org/a4j">

<ui:composition template="/WEB-INF/template/template.xhtml">
  <f:metadata>
    <f:event type="preRenderView" listener="#{zanataRoleSearch.loadRoles}"/>
    <f:event type="preRenderView" listener="#{identity.checkRole('admin')}"/>
  </f:metadata>

  <ui:define name="page_title">#{msgs['jsf.ManageRoles']}</ui:define>

  <ui:define name="center_content">
    <zanata:confirm-modal id="deleteRoleModal"
      title="#{msgs['jsf.role.delete.title']}"
      message="#{msgs['jsf.AreYouSureYouWishToDeleteThisRoleThisActionCannotBeUndone']}"
      onresponse="onDeleteRoleResponse" />

    <a4j:jsFunction name="deleteRole" action="#{identityManager.deleteRole(role)}" render="roles-form">
      <a4j:param name="val1" assignTo="#{role}"/>
    </a4j:jsFunction>

    <script type="text/javascript">
      var selectedRole;
      function setSelectedRole(role) {
        selectedRole = role;
      }
      function onDeleteRoleResponse(del) {
        if (del) {
          deleteRole(selectedRole);
        } else {
          selectedRole = null;
        }
        zanata.modal.hide('#deleteRoleModal');
      }
    </script>
    <div class="g--centered">
      <div class="g__item w--1-m w--1-2-l w--1-2 l--push-bottom-half">
        <p class="txt--meta l--push-all-0">
          <a href="/admin/home">
            #{msgs['jsf.Administration']}
          </a>
        </p>

        <h1 class="l--push-all-0">#{msgs['jsf.ManageRoles']}</h1>

        <div class="panel l--push-top-1">
          <div class="panel__header">
            <div class="panel__header__actions">
              <div id="rolemanage-more-actions"
                class="dropdown dropdown--header dropdown--small dropdown--right dropdown--inline js-dropdown">
                <a  class="dropdown__toggle js-dropdown__toggle" href="#"
                  title="#{msgs['jsf.tooltip.MoreActions']}">
                  <i class="i i--ellipsis"></i>
                </a>
                <ul class="dropdown__content js-dropdown__content"
                  role="content"
                  aria-labelledby="dropdownContent">
                  <li>
                    <h:link styleClass="i__item--right"
                      outcome="/admin/roledetail.xhtml"
                      rendered="#{identity.hasPermission('seam.account', 'create')}"
                      value="#{msgs['jsf.CreateRole']}">
                      <i class="i i--add i__item__icon"></i>
                    </h:link>
                  </li>
                </ul>
              </div>
            </div>
            <h2 class="panel__heading">#{msgs['jsf.admin.managerole.header']}</h2>
          </div>
          <h:form styleClass="l--push-bottom-0" id="roles-form">
            <ul class="list--stats">
              <ui:repeat value="#{zanataRoleSearch.roles}" var="role">
                <li class="list__item--actionable">
                  <div class="list__item__action">
                    <div
                      class="dropdown dropdown--small dropdown--inline dropdown--single list__item__dropdown js-dropdown">
                      <a href="#" title="Options"
                        class="dropdown__toggle js-dropdown__toggle txt--meta">
                        <span class="is-invisible">Options</span>
                      </a>
                      <ul class="dropdown__content js-dropdown__content">
                        <ui:fragment
                          rendered="#{identity.hasPermission('seam.role', 'delete') and accountRoleDAO.findByName(role).roleType.toString() ne 'AUTO'}">
                          <li>
                            <a href="#" class="i__item--right txt--danger" onclick="setSelectedRole('#{role}')"
                              data-toggle="modal" data-target="#deleteRoleModal">
                              #{msgs['jsf.Delete']}
                              <i class="i i--cancel i__item__icon"></i>
                            </a>
                          </li>
                        </ui:fragment>
                      </ul>
                    </div>
                  </div>
                  <h:link outcome="/admin/roledetail.xhtml"
                    disabled="#{not identity.hasPermission('seam.role', 'update') or accountRoleDAO.findByName(role).roleType.toString() eq 'AUTO'}">
                    <div class="list__item__content">
                      <div class="list__item__info">
                        <h3 class="list__title">#{role}
                        <h:panelGroup layout="span" rendered="#{not zanataRoleSearch.getRoleGroups(role).isEmpty()}"
                          styleClass="txt--meta l--push-left-half">[#{zanataRoleSearch.getRoleGroups(role)}]</h:panelGroup>
                        </h3>
                      </div>
                    </div>
                    <f:param name="role" value="#{role}" />
                  </h:link>
                </li>
              </ui:repeat>
            </ul>
          </h:form>
        </div>
      </div>
    </div>
  </ui:define>

</ui:composition>
</html>
